package com.gg.user.gguser.dao;

import com.gg.user.gguser.dataobject.GgNewsDataobject;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
@CacheNamespace
public interface GgNewsDaoMapper {

    /**
     * 获取一共多少个
     * @return
     */
    @Select("select count(*) from gg_news")
    Integer getNewsSelectCount();

    @Select("select gg_n_id as ggNId, gg_n_title as ggNTitle, gg_n_introduction as ggNIntroduction, gg_n_type as ggNType, date_format(gg_n_time, '%Y-%m-%d  %H:%i:%s') as ggNTime from gg_news  order by gg_n_time desc limit #{page},#{pageNumber}")
    List<GgNewsDataobject> getNewsSelect(@Param("page") Integer page,@Param("pageNumber") Integer pageNumber);

    @Select("select gg_nicheng as ggNId, gg_n_title as ggNTitle, gg_n_introduction as ggNIntroduction, gg_n_type as ggNType, gg_n_content as ggNContent, gg_n_submitter as ggNSubmitter, date_format(gg_n_time, '%Y-%m-%d %H:%i:%s') as ggNTime,gg_n_update as ggNUpdate,gg_n_range as ggNRange from gg_news gn left join gg_user gu on gn.gg_n_submitter = gu.gg_id where gg_n_id = #{itemsId} ")
    Map<Object,Object> getNewSelectItems(@Param("itemsId") Integer itemsId);

    // 发送消息
    @Insert("insert into gg_news (gg_n_title, gg_n_introduction,gg_n_type,gg_n_content,gg_n_submitter,gg_n_range) values(#{ggNTitle},#{ggNIntroduction},#{ggNType},#{ggNContent},#{ggNSubmitter},#{ggNRange})")
    @Options(useGeneratedKeys=true, keyProperty="ggNId", keyColumn="gg_n_id")
    //void addNewSelectItems(@Param("range")String range,@Param("count")String count,@Param("introduction")String introduction,@Param("title")String title,@Param("type")String type, @Param("submitter")String submitter);
    void addNewSelectItems(GgNewsDataobject ggNewsDataobject);

    // 删除消息
    @Delete("delete from gg_news where gg_n_id=#{id} and gg_n_submitter = #{ggIdUser}")
    Integer delectNewSelectItems(@Param("ggIdUser")String ggIdUser,@Param("id")Integer id);

    // 插入用户阅读表  用户和信息对应表
    @Insert("insert into gg_news_read (gg_new_id,gg_n_i_user) values(#{ggNewId},#{ggNIUser})")
    Integer installNewItemsRead(@Param("ggNewId")Integer ggNewId,@Param("ggNIUser")String ggNIUser);
}
